local extension = Package:new("test3")
extension.extensionName = "aj_test"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["test3"] = "测试·三",
}

local jiepade = General:new(extension, "test3__jiepade", "test_hu", 4)

Fk:loadTranslationTable{
  ["test3__jiepade"] = "杰帕德",--名字
  ["#test3__jiepade"] = "永屹之壁",--称号
  ["designer:test3__jiepade"] = "zuozhe",--作者
  ["cv:test3__jiepade"] = "cv",--cv
  ["illustrator:test3__jiepade"] = "huashi",--画师

  ['~test3__jiepade'] = '不能保护大家了……',
}

local shuyu = fk.CreateTriggerSkill{
  name = "test3__shuyu",
  events ={fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and data.from then
      local targets = table.filter(player.room:getAlivePlayers(), function(p)
        print(p.general,player:distanceTo(p))
        return player:distanceTo(p) < 2
      end)
      return table.contains(targets,target)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@@test3__shuyu-turn",1)
    room:setPlayerMark(player,"test3__shuyu-lx",judge.card.type)
    room:setPlayerMark(player,"@test3__shuyu",Fk:translate(judge.card:getSuitString(true))..Fk:translate(judge.card:getTypeString(true)))
    if table.find(room:getOtherPlayers(player),function (t)
        return t.hp > player.hp
      end) == nil then
      for _, t in ipairs(room:getAlivePlayers()) do
        room:damage({
          from = player,
          to = t,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        })
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill("rfenghou__jinzun") then return false end
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if (move.to == player.id and move.toArea == Card.PlayerEquip)
        or (move.from == player.id and info.fromArea == Card.PlayerEquip) then
          return Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if move.to == player.id and move.toArea == Card.PlayerEquip and Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
          for _, skill in ipairs(player.player_skills) do
            if skill.attached_equip and Fk:cloneCard(skill.attached_equip).sub_type == Card.SubtypeWeapon then
              if Fk.skills[skill] and player:hasSkill(skill, true) then
                player.room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
              end
              if Fk.skills[skill.name] and player:hasSkill(skill.name, true) then
                player.room:handleAddLoseSkills(player, "-"..skill.name, nil, true, false)
              end
            end
          end
          for i = 0, 30, 1 do
            local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
            if not player:hasSkill(name, true) then
              player:setSkillUseHistory(name, 0, Player.HistoryGame)
              player.room:setPlayerMark(player, ""..name, Fk:getCardById(info.cardId).attack_range ~= nil and Fk:getCardById(info.cardId).attack_range or 1)
              player.room:setPlayerMark(player, ""..name.."record", Fk:getCardById(info.cardId).name) --记录一下卡牌名字，用来定位删除的技能
              player.room:handleAddLoseSkills(player, name, nil, true, false)
              break
            end
          end
        elseif move.from == player.id and info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
          for i = 0, 30, 1 do
            local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
            if player:hasSkill(name, true) and player:getMark(""..name.."record") == Fk:getCardById(info.cardId).name then
              player:setSkillUseHistory(name, 0, Player.HistoryGame)
              player.room:setPlayerMark(player, ""..name, 0)
              player.room:setPlayerMark(player, ""..name.."record", 0)
              player.room:handleAddLoseSkills(player, "-"..name, nil, true, false)
              break
            end
          end
        end
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    for _, skill in ipairs(player.player_skills) do
      if skill.attached_equip and Fk:cloneCard(skill.attached_equip).sub_type == Card.SubtypeWeapon then
        if Fk.skills[skill] and player:hasSkill(skill, true) then
        player.room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
        end
        if Fk.skills[skill.name] and player:hasSkill(skill.name, true) then
          player.room:handleAddLoseSkills(player, "-"..skill.name, nil, true, false)
        end
      end
    end
    for _, e in ipairs(player.player_cards[Player.Equip]) do
      if Fk:getCardById(e).sub_type == Card.SubtypeWeapon then
        for i = 0, 30, 1 do
          local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
          if not player:hasSkill(name, true) then
            player:setSkillUseHistory(name, 0, Player.HistoryGame)
            player.room:setPlayerMark(player, ""..name, Fk:getCardById(e).attack_range ~= nil and Fk:getCardById(e).attack_range or 1)
            player.room:setPlayerMark(player, ""..name.."record", Fk:getCardById(e).name) --记录一下卡牌名字，用来定位删除的技能
            player.room:handleAddLoseSkills(player, name, nil, true, false)
            break
          end
        end 
      end
    end
  end,

  on_lose = function (self, player, is_death)
    for i = 0, 30, 1 do
      local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
      if player:hasSkill(name, true) then
        player:setSkillUseHistory(name, 0, Player.HistoryGame)
        player.room:setPlayerMark(player, ""..name, 0)
        player.room:setPlayerMark(player, ""..name.."record", 0)
        player.room:handleAddLoseSkills(player, "-"..name, nil, true, false)
      end
    end
  end,
}

Fk:loadTranslationTable{
  ["test3__shuyu"] = "戍御",
  [":test3__shuyu"] = "当你距离1以内的一名角色成为【杀】的目标或使用者时，你可令该角色于本回合结束前获得你场上所有武器与防具的效果。",

  ["$test3__shuyu1"] = "没什么能阻止我。",
  ["$test3__shuyu2"] = "这点疼痛不足挂齿。",

  ["@test3__shuyu"] = "倾注",
}


return extension